<?php
declare (strict_types = 1);

namespace app\command;

use Alipay\EasySDK\Kernel\Factory;
use app\facade\BaiDuFacade;
use app\facade\CosFacade;
use app\facade\CurlFacade;
use app\facade\HasherFacade;
use app\facade\OpenFacade;
use app\facade\OssFacade;
use app\facade\ALiPayFacade;
use app\facade\SmsFacade;
use app\facade\StringFacade;
use app\facade\TrtcFacade;
use app\facade\UploadFacade;
use app\facade\AppletsFacade;
use app\facade\WechatpayFacade;
use app\facade\ZhiMaDaiLiFacade;
use app\model\communal\CourseModel;
use app\model\communal\UserStatisticsModel;
use app\service\basic\auth\JWTGuard;
use app\service\logic\common\course\CourseService;
use app\service\logic\common\user\CoinService;
use app\service\logic\common\user\InviteService;
use app\service\logic\common\user\StatisticsService;
use app\tools\CosTool;
use Carbon\Carbon;
use Detection\MobileDetect;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Category;
use Qcloud\Cos\Client;
use Tencent\TLSSigAPIv2;
use thans\jwt\facade\JWTAuth;
use think\db\Query;
use think\facade\Cache;
use think\console\Input;
use think\console\Output;
use think\console\Command;
use app\model\communal\AdminModel;
use think\facade\Db;
use think\facade\Log;
use WeChatPay\Formatter;
use WeChatPay\Crypto\Rsa;

class TestCommand extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('test')
            ->setDescription('test command');
    }

    protected function execute(Input $input, Output $output)
    {
        $temp = '';

        // 推送模板消息  Vb_E8dNua3z7d2gzUf-CZGUAIWZ7PhVMs8F1vcqARxY
        // $result = AppletsFacade::build_uniform_send_msg2('oXDg_4zR2aPCpEH1YAofYL77A74M', '您好,有访客进行操作!', '访客xyz909!', '金介子获客系统!','点击按钮 推荐TA!', '嘎嘎嘎嘎嘎','2022-02-02 00:00:00', '请尽快跟进!', 'pages/index/visit_ai?id=2');
        // dd($result);
        // $adminIds = invoke(ContentService::class)->getType5ByKey('return_admin_ids');

        // $result = AppletsFacade::build_uniform_send_msg1(['oXDg_4zR2aPCpEH1YAofYL77A74M', '您好,有访客进行操作!', '访客xyz909!', '金介子获客系统!','点击按钮 推荐TA!', '嘎嘎嘎嘎嘎','2022-02-02 00:00:00', '请尽快跟进!', 'pages/index/visit_ai?id=2']);
        // event('PublicNotice', ['method' => 'build_uniform_send_msg1', 'params' => ['oXDg_4zR2aPCpEH1YAofYL77A74M', '您好,有访客进行操作!', '访客xyz909!', '2022-02-02 00:00:00', '请尽快跟进!', 'pages/index/visit_ai?id=2']]);
        // require_once 'Mobile_Detect.php';
        // $detect = new \Mobile_Detect();
        // $detect->isIphone();
        // $detect = new MobileDetect();
        // $res = $detect->isMobile();

        /*
         * trtc
         */
        // TrtcFacade::removeUserRequest(54141,['user_94511413']); //ttt
        // TrtcFacade::dismissRoomRequest(54141); //ttt

        // user sig
        // $temp = TrtcFacade::userSig('user_1');
        // dd($temp);

        // 订单编号
        // $temp = StringFacade::createStringById('999999999999999999999999999999999999999999999', 'OM', 16);

        /*
         * alipay
         */
        // app支付
        // $temp = ALiPayFacade::paymentAppPay(); dd($temp);
        // 电脑网站支付
        // $outTradeNo = md5('TEMP' . Carbon::now()->timestamp);
        // $temp = ALiPayFacade::paymentPagePay([
        //     'notify_url' => config('domain.api') . '/callback/alipay',
        //     'subject' => 'just play',
        //     'outTradeNo' => $outTradeNo,
        //     'totalAmount' => '0.1'
        // ]); dd($temp);

        // 元心币明细
        invoke(CoinService::class)->back([
            'user_id' => 13,
            'coin_count' => 10000,
            'remark' => '白给的',
        ]);

        // $temp = array (  'gmt_create' => '2022-05-26 14:39:53',  'charset' => 'UTF-8',  'gmt_payment' => '2022-05-26 14:47:06',  'notify_time' => '2022-05-26 14:47:07',  'subject' => '多元智能题型',  'sign' => 'vfxXDXkve0SxU0gHqCbSnUztIx1GmIk7Ao8r6+KwwiZPT+NT0k/AHF3a53j4fmfodfDNMVsAmABDl4P6Gm8A7M538HCUBA7OjJOVvUWIv7NKJa3LC9DPObRbA+KQmXyz0fSiUvQ0c+vDBF/NwTovs7ZADNkBgDT+UKZJoGGD3dOKgYIj17AfJMDLG4ZbQJu6okcGZ+EjVpyLRGiZ766EzsZ/zw2F1sqxjig3/fzcGdJThWUAkHYz2N3LZTPqOue1+qU0ukl7IDffXBtvXYNQxwPG+Wpo2RBgy/0IkYsMyrMhBx3rcPu3eaO2wSeVEFrD1FFBrmZYARJ04nNDeZvdIg==',  'buyer_id' => '2088622958777205',  'passback_params' => '%7B%22order_type%22%3A1%7D',  'invoice_amount' => '0.01',  'version' => '1.0',  'notify_id' => '2022052600222144707077200542500062',  'fund_bill_list' => '[{\"amount\":\"0.01\",\"fundChannel\":\"ALIPAYACCOUNT\"}]',  'notify_type' => 'trade_status_sync',  'out_trade_no' => '99f86cc886ebf4ad198a4804a62ec0b5',  'total_amount' => '0.01',  'trade_status' => 'TRADE_SUCCESS',  'trade_no' => '2022052622001477200503108154',  'auth_app_id' => '2021000119695999',  'receipt_amount' => '0.01',  'point_amount' => '0.00',  'app_id' => '2021000119695999',  'buyer_pay_amount' => '0.01',  'sign_type' => 'RSA2',  'seller_id' => '2088621958742367',);
        // $temp['notify_url'] = config('domain.api') . '/callback/alipay';
        // ALiPayFacade::paymentCommonQuery('0865be234bb369d367eacc442152fc31');
        // dd(json_decode(urldecode($temp['passback_params']), true));
        // event('OrderMultiPaySuccess', ['out_trade_no' => '97ca1c2a8e2d381a2bc7f721a1cf80b2', 'trade_status' => '嘎嘎嘎']); // 可队列
        // $conversionRate = config('logic.coin_conversion_rate'); dd($conversionRate);

        // todo 组装数据
        // $temp = invoke(CourseService::class)->buildChapterSectionVideo(3); dd($temp);
        // $temp = app_path('cert'.DIRECTORY_SEPARATOR.'wx'); dd($temp);

        // 微信支付
        // dd(Carbon::now()->timestamp);
        // $temp = WechatpayFacade::v3PayTransactionsApp([]);
        // $temp = WechatpayFacade::v3AppSign($temp['prepay_id']); dd($temp);
        // $merchantPrivateKeyFilePath = 'file:///path/to/merchant/apiclient_key.pem';
        // $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath);
        // WechatpayFacade::getSign();exit;
        // 解签
        // WechatpayFacade::decrypt();exit;
        // WechatpayFacade::v3TransferBatches([
        //     'out_batch_no' => md5('Temp_batch' . Carbon::now()->timestamp),
        //     'total_amount' => 1,
        //     'total_num' => 1,
        //     'transfer_detail_list' => [
        //         [
        //             'out_detail_no' => md5('Temp_detail' . Carbon::now()->timestamp),
        //             'transfer_amount' => 1 * 100,
        //             'transfer_remark' => '转账备注',
        //             'openid' => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
        //         ]
        //     ],
        // ]);

        // 微信回调
        // $temp = array (
        //     'id' => 'e592a9c8-4de1-526f-8080-77814c4dab43',
        //     'create_time' => '2022-05-31T15:33:59+08:00',
        //     'resource_type' => 'encrypt-resource',
        //     'event_type' => 'TRANSACTION.SUCCESS',
        //     'summary' => '支付成功',
        //     'resource' =>   array (
        //         'original_type' => 'transaction',
        //         'algorithm' => 'AEAD_AES_256_GCM',
        //         'ciphertext' => 'Jqwc+sgF0dwey2NOqjTa1YS2/YtSg9CnZEw2NRhLPZzOX+mZljSAhqXsXa3Q71HcbaQThksWM8g/wn4fFQK5a9fV6/LaEWjjG+kIbdVpyYvt9+fA+G9HNolW+2xOnaVKWtk6qF2FBu3q9VP3nzBpoGKMHZEyaVE3r73YGV4G2pMtZkljSGMNnL3yKGC9I9mv4wDeuqkcKma5gIsCcsgc6gU7Ms8OhS2CsPrHJFy8sTcr0CE7Fy4AYi/7S/QtaJVu+OcjRyue9jtEYGcOjTUtVnM6QETvULrgdqSdSPVK5sd1SgOVABxIyiA41kuuh4CgNlP+HRDonFO94Geq2fGq9R1ggAdOmTfui6RcPEbKYS+Wv5I+V6cokPX7XensFdvIU6yJTq1Ie8+l4Na95dPatLTtB6jXvDhdgI9GnFXO1PD6Kt7Wx7aiUVRNU8Tsd3hrOL5mgZqhavo/o9MRZK8Fefv6lzaqQ8Oivqh2L3c1BQioD/lIRQ2jSODPHoz768VX/mVuz2TnwUAM9QaFjOSgIuKo3fIEZhY/HbSyFON6Jvx47vKXcHCG91pfX3Q/Un74idfWomnBZARtVeITOCjbp9ZGuqP0+gJ8MVD8p5d3Ek1XUcUvI9p0',
        //         'associated_data' => 'transaction',
        //         'nonce' => 'pidbN5StpfMZ',
        //         ),);

        // refund params
        // $temp = array (
        //     'id' => '823d887d-4816-5708-97e3-d3636f609e64',
        //     'create_time' => '2022-06-02T16:05:39+08:00',
        //     'resource_type' => 'encrypt-resource',
        //     'event_type' => 'REFUND.SUCCESS',
        //     'summary' => '退款成功',
        //     'resource' =>   array (
        //         'original_type' => 'refund',
        //         'algorithm' => 'AEAD_AES_256_GCM',
        //         'ciphertext' => 'p+qhc2URgKfmvaHl/k0/7f8x8gUkzAnMy/nzJtCmTveXu9UJ8sM5gVEBDdvwGTWFxVlS14d+jfv2L6k2JT/+CCSdRzcQnlY22uyTzx5dY0sbHIU0iyBSOXLg+ULCatEHqJDR4GPvizL0XTFKHD180RPHGtgB+npBLH24jgt2TdNkdwb33ZaEKoLosAXU45pXn222CcioB+H4tAmZgaJNXMT6PO3imPWV1jlYuAU0GR7AV7I7fJ12l91LbwYgj500Zr0oiXs9523zcEn2mHt9ofEc1pUJCHRVQOr7R5ZPv4m87Nwb/rrm23u5Htj8EZ3Aml6VlR/PS1yLYyNnBAfOhzXotaE/DOs2C1wYswOnh6PFdi5xccU1O+S5gGEDZP/VcN3bLCf/j3EXKLOINh6POGGBrKnmCaSgEIlpYHNREf6pKw96ZlgF7uKGdFDZkIxIe+iZwiWWlPPuCzgT7PaDWqfzUBq+FL8/tITsjHlhgbqNYWsB5ZBFSzquZEz3j0zmwKcMhMgY5zwqFSqfHOZCU/L3pa2v2wHam0Ezqg==',
        //         'associated_data' => 'refund',
        //         'nonce' => 'cq7dLhnLKYtG',
        //         ),);

        // open api
        // OpenFacade::code2Session('123445');

        // user statistics
        // invoke(StatisticsService::class)->accrueCost(70, 10000);
        // $temp = invoke(StatisticsService::class)->getCoinByAccrueCost(0, 1.5); dd($temp);
        // invoke(CoinService::class)->back(['user_id' => 1, 'coin_count' => '15000.00', 'type' => 1]);
        // $temp = UserStatisticsModel::whereIn('user_id', [999])->sum('accrue_cost'); dd($temp);
        // $temp = invoke(InviteService::class)->getAccrueCostByFrom(1); dd($temp);

        // 指令输出
        $output->writeln('done');
    }
}
